package com.ps.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author gt
 * @类说明：
 * @date 2020/10/27 14:48
 */
@Configuration
@EnableSwagger2//启动swagger
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 扫描的包，很重要
                .apis(RequestHandlerSelectors.basePackage("com.ps"))//指定扫描controller包
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 定义Api信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("系统用户API")//接口标题
                .description("新增系统用户，查询系统用户，修改系统用户")//接口具体描述
                .termsOfServiceUrl("http://127.0.0.1:8080/")//调用服务地址
                .contact(new Contact("我们","http://test.com","2374449186@qq.com"))//联系我们信息
                .version("version 1.0")//定义版本号
                .build();
    }
}
